const state = {
	userInfo: uni.getStorageSync('userInfo') ? uni.getStorageSync('userInfo') : null,
	employer: null
};
const getters = {
	getEmployer(state) {
		return state.employer
	}
}

const mutations = {
	setUserInfo(state, param) {
		state.userInfo = param;
		if (null === param) {
			uni.removeStorageSync('token');
			uni.removeStorageSync('userInfo');
		} else {
			uni.setStorageSync('userInfo', param);
		}
	},
	SET_EMPLOYER(state, employer) {
		state.employer = employer
	},
	updateUserInfo(state, param) {
		let userInfo = state.userInfo;
		state.userInfo = Object.assign(userInfo, param);
		uni.setStorageSync('userInfo', state.userInfo);
	},
};

import {
	getUserInfo,
} from '@/api/mine.js'
const actions = {
	actionGetUserInfo({
		commit,
		state
	}) {
		return new Promise((resolve, reject) => {
			getUserInfo().then((res) => {
				if (state.userInfo) {
					commit('updateUserInfo', res.data);
				} else {
					commit('setUserInfo', res.data);
				}
				resolve(true)
			}).catch((res) => {
				reject(false)
			})
		})
	},
};


export default {
	state,
	mutations,
	actions,
	getters
}